import java.util.Objects;

public class Student {
    private String name;
    private int age;

    @Override
    public String toString() {
        return "Student{" + "name='" + name + '\'' + ", age=" + age + '}';
    }

    @Override
    //equal方法重写，比较两个对象内容是否一样，一样返回true
    public boolean equals(Object o) {
        //1.先判断this 与o的地址是否相同，相同返回true
        if (this == o) return true;
        //2.如果o指向Null或者this与o的类型不一样，返回false
        //                    学生类型
        if (o == null || this.getClass() != o.getClass()) return false;
        //3.如果地址不同，类型一样，开始比较内容
        Student student = (Student) o;//先把o强制类型转换为student类型，因为o默认为object类型
        return age == student.age && Objects.equals(name, student.name);
    }

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
}
